/**
 * Created by bruce on 17/8/2.
 */
var path = require('path');
var webpack = require('webpack');
var OpenBrowserPlugin = require('open-browser-webpack-plugin');


module.exports = {
  entry: './app/main.js', // 入口文件路径
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'bundle.js'
  },
  devServer: {
    inline: true,
    port: 3333,
    hot: true
  },
  resolve: {
    modules: [
      path.join(__dirname, "node_modules")
    ],
    extensions: ['.js', '.scss', '.json', '.css'],
  },
  resolveLoader: {
    moduleExtensions: ["-loader"]
  },
  module: {
    rules: [
      {
        test: /\.js$/, // babel 转换为兼容性的 js
        exclude: /node_modules/,
        use: [{
            loader: 'babel-loader',
            options: {
              presets: ['react', 'latest', 'es2015', 'stage-0'],
              plugins: ["transform-decorators-legacy"]
            },
          }
        ]
      },
      {
        test: /\.(scss|sass|css)$/,
        use: [
            "style-loader",
            "css-loader",
            "sass-loader"
        ],
      },
      {
        test: /\.(jpg|png|svg)$/,
        use: [
          {
            loader: "url-loader",
            options: {
              limit: 8192,
            }
          }
        ],
      },
      {
        test: /\.(eot|woff|woff2|ttf)([\?]?.*)$/,
        use: [
          "file-loader"
        ]
      },
      { 
        test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
        use: [
          {
            loader: "url-loader",
            options: {
              limit: 10000,
              mimetype: "application/font-woff"
            }
          }
        ],
      },
      {
        test: /\.css$/,
        use: [
          "style-loader",
          "css-loader"
        ]
      },
    ]
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new OpenBrowserPlugin({ url: 'http://localhost:3333' })
  ]
}
